# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=djview
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.12
pkgrel=2
pkgdesc='Portable DjVu viewer (mingw-w64)'
url='https://djvu.sourceforge.io/djview4.html'
license=('GPL')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
depends=("${MINGW_PACKAGE_PREFIX}-djvulibre"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-libtiff")
makedepends=("${MINGW_PACKAGE_PREFIX}-qt5-tools"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://downloads.sourceforge.net/djvu/${_realname}-${pkgver}.tar.gz")
sha256sums=('5673c6a8b7e195b91a1720b24091915b8145de34879db1158bc936b100eaf3e3')
conflicts=("${MINGW_PACKAGE_PREFIX}-djview4")
provides=("${MINGW_PACKAGE_PREFIX}-djview4")
replaces=("${MINGW_PACKAGE_PREFIX}-djview4")

prepare() {
  cd ${_realname}4-${pkgver}
  NOCONFIGURE=1 ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  cp -rf ${_realname}4-${pkgver} build-${MSYSTEM} && cd ${srcdir}/build-${MSYSTEM}

  export QMAKE=${MINGW_PREFIX}/bin/qmake.exe
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  cp src/release/djview.exe "${pkgdir}${MINGW_PREFIX}"/bin/djview4.exe
  ln -s "${pkgdir}${MINGW_PREFIX}"/bin/djview4.exe "${pkgdir}${MINGW_PREFIX}"/bin/djview.exe
}
